package com.zt.dev.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zt.dev.common.ResponseUtils;
import com.zt.dev.common.ServerResponse;
import com.zt.dev.system.service.SystemStructureService;
import com.zt.dev.system.vo.SystemStructureVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 30378
 * <p>
 * 体系结构的基本信息的维护
 */
@Controller
public class SystemStructureController {

    @Autowired
    private SystemStructureService structureService;

    /**
     * 新增体系
     * @return
     */
    @PostMapping("/addSystem")
    @ResponseBody
    public ServerResponse addSystem(SystemStructureVo structure) {
        int i = structureService.addSystem(structure);
        return ResponseUtils.commonResponse(i, "体系创建");
    }

    /**
     * 批量删除体系
     **/
    @PostMapping("/delSystem")
    @ResponseBody
    public ServerResponse delSystemById(Integer[] ids) {
        if (ids.length > 0) {
            int i = structureService.delSystemById(ids);
            return ResponseUtils.commonResponse(i, "体系删除");
        } else {
            return ServerResponse.createByErrorMessage("删除体系id为空！");
        }
    }

    /**
     * 修改体系基本信息
     */
    @PostMapping("/editSystemInfo")
    @ResponseBody
    public ServerResponse editSystemInfo(SystemStructureVo structure) {
        if (structure.getId() != null) {
            int i = structureService.editSystemInfo(structure);
            return ResponseUtils.commonResponse(i, "体系信息修改");
        } else {
            return ServerResponse.createByErrorMessage("体系修改ID为空，修改失败！");
        }
    }

    /**
     * 查找所有体系
     **/
    @PostMapping("/findAllSystems")
    @ResponseBody
    public ServerResponse findAllSystems(Integer id, Page page) {
        if (id != null) {
            return ServerResponse.createBySuccess(structureService.findAllSystemById(id));
        } else {
            return ServerResponse.createBySuccess(structureService.findAllSystemsByPage(page));
        }
    }



    // 体系的导入

    // 体系的导出
}
